{# SPDX-FileCopyrightText: © 2021 Sarita Singh <saritasingh.0425@gmail.com>

   SPDX-License-Identifier: GPL-2.0-only

   ScanCode has no plugin for custom template but it has a builtin to write scan results 
   using a custom template.
   @see https://scancode-toolkit.readthedocs.io/en/latest/tutorials/how_to_format_scan_output.html#custom-output-format 
#}

{
    "licenses": 
    [
        {%- if licenses -%}
            {%- for key, license in licenses.items() -%}
                {
                    "key": "{{ license.spdx_license_key }}",
                    "score": {{ license.score }},
                    "name": "{{ license.name }}",
                    "text_url": "{{ license.text_url }}",
                    "start_line": {{ license.start_line }},
                    "matched_text": {{ license.matched_text|tojson }}
                }
                {%- if loop.nextitem and not loop.last -%},{%- endif -%}
            {%- endfor -%}
        {%- endif -%}
    ],
    "copyrights": 
    [
    {%- if files.license_copyright -%}
        {%- set copyright_ns = namespace(print=false) -%}
        {%- for path, data in files.license_copyright.items() -%}
            {%- for row in data -%}
                {%- if row.what != 'license' -%}
                    {%- if copyright_ns.print -%},{%- else -%}{%- set copyright_ns.print = true -%}{%- endif -%}
                    {
                         "value": {{ row.value|tojson }},
                         "start": {{ row.start }}
                    }
                {%- endif -%}
            {%- endfor -%}
        {%- endfor -%}
    {%- endif -%}
    ],
    "holders": 
    [
        {%- if files.infos -%}
            {%- set holder_ns = namespace(print=false) -%}
            {%- for path, row in files.infos.items() -%}
                {%- if row.holders -%}
                    {%- for data in row.holders -%}
                        {%- if holder_ns.print -%},{%- else -%}{%- set holder_ns.print = true -%}{%- endif -%}
                        {
                             "value": {{ data.holder|tojson }},
                             "start": {{ data.start_line }}
                        }
                    {%- endfor -%}
                {%- endif -%}
            {%- endfor -%}
        {%- endif -%}
    ]
}
